/**
 * Copyright (c) 2003-2017 Ben Lau
 * All rights reserved.
 */
package benworks.bookcode.jvm.chapter4;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liubin
 *
 */
public class FillHeap {

	static class OOMObject {
		public byte[] placeholder = new byte[64 * 1024];
	}

	public static void fillHeap(int num) throws InterruptedException {
		List<OOMObject> list = new ArrayList<>();
		
		for (int i = 0; i < num; i++) {
			//稍作延时，令监视曲线的变化更加明显
			Thread.sleep(200);
			list.add(new OOMObject());
		}
		
		System.gc();
	}
	
	public static void main(String[] args) throws InterruptedException {
		fillHeap(5000);
	}
}
